<script setup>
import {ref} from 'vue'
import {onLoad,onReachBottom,onPullDownRefresh} from '@dcloudio/uni-app'
import {reqGoodsList} from '../api/goods.js'

const dataList = ref([])
let isFinish = ref(false)
const requestData = ref({
	page:1,
	limit:10,
	categoryId:'',
	category2Id:''
})
let total = ref()
let isLoading = ref(false)
onLoad(async(options)=>{
	// console.log(options);
	Object.assign(requestData.value,options)
	// console.log(requestData.value);
	await getGoodsList()
})

const getGoodsList = async()=>{
	isLoading.value = true
	const {data} = await reqGoodsList(requestData.value)
	isLoading.value =false
	total.value = data.total
	dataList.value.push(...data.records)
}
// 触底加载更多
onReachBottom(async()=>{
	if(isLoading.value===true) return
	if(dataList.value.length===total.value){
		isFinish.value = true
		return
	}
	requestData.value.page++
	// console.log(requestData.value.page);
	await getGoodsList()
})
// 下拉加载更多
onPullDownRefresh(async()=>{
	dataList.value=[]
	isFinish.value=false
	total.value=0
	requestData.value.page=1
	await getGoodsList()	
	uni.stopPullDownRefresh()
})
</script>


<template>
	<view class="good-list">
		<goods-list v-bind:guessList="dataList" v-bind:isFinish="isFinish"></goods-list>
	</view>
</template>

<style lang="scss" scoped>
.good-list{
	padding: 20rpx 10rpx;
}
</style>
